package fuzion24.device.vulnerability.vulnerabilities.kernel;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import fuzion24.device.vulnerability.util.CPUArch;
import fuzion24.device.vulnerability.vulnerabilities.VulnerabilityTest;

public class CVE_2014_4943 implements VulnerabilityTest {
    static {
        System.loadLibrary("CVE-2014-4943");
    }

    @Override
    public List<CPUArch> getSupportedArchitectures() {
        ArrayList<CPUArch> archs = new ArrayList<>();
        archs.add(CPUArch.ARM);
        archs.add(CPUArch.ARM7);
        archs.add(CPUArch.ARM8);
        return archs;
    }

    @Override
    public String getCVEorID() {
        return "CVE-2014-4943";
    }

    private native int checkL2TP();

    @Override
    public boolean isVulnerable(Context context) throws Exception {
        int checkVal = checkL2TP();

        if(checkVal == 0) {
            return false;
        }else if(checkVal == 1) {
            return true;
        }else {
            throw new Exception("Error running test. Errno: " + checkVal);
        }
    }
}